<template>
  <div>
    <DeHeader>联合登录</DeHeader>
    <section class="container">
      <nav class="tab">
        <a
          @click="hasAccount = true"
          :class="{ active: hasAccount }"
          href="javascript:;"
        >
          <i class="iconfont icon-bind" />
          <span>已有小兔鲜账号，请绑定手机</span>
        </a>
        <a
          @click="hasAccount = false"
          :class="{ active: !hasAccount }"
          href="javascript:;"
        >
          <i class="iconfont icon-edit" />
          <span>没有小兔鲜账号，请完善资料</span>
        </a>
      </nav>
      <div class="tab-content" v-if="hasAccount">
        <CallbackBind  :name="name" :nameimg="nameimg"/>
      </div>
      <div class="tab-content" v-else>
        <CallbackPatch />
      </div>
    </section>
    <Defooter></Defooter>
  </div>
</template>
<script>
import Defooter from "./Defooter.vue";
import DeHeader from "./DeHeader.vue";
import CallbackBind from "./CallbackBind.vue";
import CallbackPatch from "./CallbackPatch.vue";
import {social} from "@/utils/api/userapi"
import qc from "qc"
export default {
  components: { DeHeader, Defooter, CallbackPatch, CallbackBind },
  data() {
    return {
      hasAccount: true,
      name:'',
      nameimg:''
    };
  },
  mounted() {
    this.checkqq();
  },
  methods: {
    checkqq() {
      //获取用户的唯一标识
      //qc.login.check()检查你是否同意qq已经登录了 true已经qq登录 false没有登录
      if (qc.Login.check()) {
        //qq已经登录需要检查账号是否已经被注册过
        qc.Login.getMe((openid) => {
          //去调用api接口检查openid是否再本网站注册过
          social(openid)
            .then((res) => {})
            .catch(() => {
              //登录失败
              //获取当前用户的信息展示再页面上
              qc.api("get_user_info").success((res) => {
                this.name = res.data.nickname;
                this.nameimg = res.data.figureurl;
              });
            });
        });
      }
    },
  },
};
</script>
<style lang="scss">
@import "@/assets/css/variables.scss";
.container {
  padding: 25px 0;
}

.tab {
  background: #fff;
  height: 80px;
  padding-top: 40px;
  font-size: 18px;
  text-align: center;

  a {
    color: #666;
    display: inline-block;
    width: 350px;
    line-height: 40px;
    border-bottom: 2px solid #e4e4e4;

    i {
      font-size: 22px;
      vertical-align: middle;
    }

    span {
      vertical-align: middle;
      margin-left: 4px;
    }

    &.active {
      color: $xtxColor;
      border-color: $xtxColor;
    }
  }
}

.tab-content {
  min-height: 600px;
  background: #fff;
}
</style>